package com.docHunt.BO.BOImpl;

import java.sql.Timestamp;
import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.docHunt.BO.UserBO;
import com.docHunt.DAO.UserDAO;
import com.docHunt.DTO.UserDTO;
import com.docHunt.Util.AppUtil;

public class UserBOImpl implements UserBO {

	private Logger logger = Logger.getLogger(UserBOImpl.class);

	@Autowired
	UserDAO userDAO;

	public boolean addUser(UserDTO userDTO) {

		try {

			String verificationCode = AppUtil.generateVerificationCode(userDTO
					.getLoginId());

			logger.debug("verificationCode : " + verificationCode);

			AppUtil.sendMail(userDTO.getLoginId(), "Welcome to DocHunt",
					"Welcome...\n Your verification code is : "
							+ verificationCode);

			userDTO.setCreatedDate(new Timestamp(new Date().getTime()));
			userDTO.setVerificationCode(verificationCode);

			userDAO.addUser(userDTO);

			return true;

		} catch (Exception e) {
			logger.error("UserBOImpl :: Exception in method addUser: ", e);
			return false;
		}
	}

	public UserDTO getUser(String loginId) {

		UserDTO userDTO = null;

		try {

			userDTO = userDAO.getUser(loginId);

		} catch (Exception e) {
			logger.error("UserBOImpl :: Exception in method getUser: ", e);

		}
		return userDTO;
	}
}
